<template>
  <div class="mobile-preview">
    <!-- 顶部状态栏 -->
    <div class="status-bar"></div>

    <!-- 顶部用户信息 -->
    <div class="user-info-panel">
        <div class="user-info">
            <div class="avatar-placeholder">
                <i class="el-icon-user-solid"></i>
            </div>
            <div class="nickname">未登录</div>
        </div>
    </div>

    <!-- 我的服务 -->
    <div class="services-panel" v-if="config && config.services">
        <h4 class="panel-title">{{ config.services.title || '我的服务' }}</h4>
        <!-- 列表根据配置的 layout 动态切换样式 -->
        <div :class="['service-list', config.services.layout === 'horizontal' ? 'layout-horizontal' : 'layout-vertical']">
            <div v-for="(item, index) in config.services.items" :key="index" class="service-item">
                <div class="icon-wrapper">
                    <el-image :src="item.icon" fit="contain" class="service-icon">
                        <div slot="error" class="image-slot">
                            <i class="el-icon-picture-outline"></i>
                        </div>
                    </el-image>
                </div>
                <span>{{ item.name }}</span>
                <i class="el-icon-arrow-right" v-if="config.services.layout !== 'horizontal'"></i>
            </div>
             <!-- 如果是横排且数量不足4个，用空的item填充以保持布局 -->
            <template v-if="config.services.layout === 'horizontal'">
                <div class="service-item-placeholder" v-for="i in (4 - config.services.items.length % 4) % 4" :key="'placeholder-' + i"></div>
            </template>
        </div>
    </div>

    <!-- 广告位占位 -->
    <div class="ad-placeholder">
        <p>广告位</p>
    </div>
  </div>
</template>

<script>
export default {
  name: "UserCenterPreview",
  props: {
    // 接收来自父组件的配置数据
    config: {
      type: Object,
      default: () => ({})
    }
  }
};
</script>

<style scoped>
.mobile-preview {
  width: 375px;
  min-height: 667px;
  background-color: #f7f8fa;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  border: 1px solid #ebedf0;
}

.status-bar {
  height: 20px;
  background-color: #fff;
}

.user-info-panel {
  background: linear-gradient(180deg, #5e8dff, #62a1ff);
  padding: 20px 15px;
  color: white;
}

.user-info {
  display: flex;
  align-items: center;
}

.avatar-placeholder {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 30px;
  margin-right: 15px;
}

.nickname {
  font-size: 18px;
  font-weight: bold;
}

.services-panel {
  margin: 15px;
  background-color: #fff;
  border-radius: 8px;
  padding: 0 15px;
}

.panel-title {
  padding: 15px 0;
  margin: 0;
  font-size: 16px;
  border-bottom: 1px solid #f7f8fa;
}

.service-list.layout-vertical .service-item {
  display: flex;
  align-items: center;
  padding: 15px 0;
  border-bottom: 1px solid #f7f8fa;
}
.service-list.layout-vertical .service-item:last-child {
  border-bottom: none;
}
.service-list.layout-vertical .service-item span {
  flex: 1;
}

.service-list.layout-horizontal {
    display: flex;
    flex-wrap: wrap;
    padding: 15px 0;
}

.service-list.layout-horizontal .service-item,
.service-list.layout-horizontal .service-item-placeholder {
    width: 25%;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 15px;
    font-size: 12px;
}
.service-list.layout-horizontal .service-item span {
    margin-top: 8px;
}

.icon-wrapper {
  width: 24px;
  height: 24px;
  margin-right: 10px;
}
.service-icon {
  width: 100%;
  height: 100%;
}
.service-list.layout-horizontal .icon-wrapper {
    width: 32px;
    height: 32px;
    margin-right: 0;
}

.ad-placeholder {
    margin: 15px;
    height: 100px;
    border-radius: 8px;
    background-color: #e9e9e9;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #999;
}
</style>
